<?php
class PXFController
{
  protected $tpl;
  
  public function __construct ()
  {
		$this->startSmarty();

		/* Smarty settings */
		$this->tpl->register_function('_','translate');
		$this->tpl->register_function('d','datef');
		$this->tpl->register_function('flashes','get_flashes');
		$this->tpl->register_function('u','build_url');

		/* General assigns */
		$this->tpl->assign('controller',  PXFInstance::$controller);
		$this->tpl->assign('action',      PXFInstance::$action);
		$this->tpl->assign('language',	  PXFInstance::$lang);
		$this->tpl->assign('current_user',PXFInstance::$user);

		/* Config settings */
		$this->tpl->assign('hostname',    PXFConfig::HOSTNAME);
		$this->tpl->assign('site',        PXFConfig::$site);
		$this->tpl->assign('languages',	  PXFConfig::$languages);
		$this->tpl->assign('NOBODY_USER', PXFConfig::NOBODY_USER);
		$this->tpl->assign('navlinks',	  PXFConfig::$navlinks);

		/* Database Loaded */
		$params['order'] = array(sprintf('title_%s',PXFInstance::$lang));
		$mod_categories = PXFModel::getModel('category');
		$categories = $mod_categories->findBy($params);
		$this->tpl->assign('categories',$categories);
	} 

	public function startSmarty()
	{
		$this->tpl = new PXFSite_Smarty();
	}

	protected static function restrictedAccess()
	{
		$mod_paccess = PXFModel::getModel('paccess');
		$condition = new PXFCondition('profile_id',PXFInstance::$user->profile_id);
		$condition->add(PXFCondition::opAND('module',PXFInstance::$controller));
		$condition->add(PXFCondition::opAND('action',PXFInstance::$action));
		if(count($mod_paccess->findBy(array('condition' => $condition))) == 0) 
		{
			$_SESSION['login_success'] = $_SERVER['REQUEST_URI'];
			$smarty = '';
			header(sprintf('Location: %s',build_url(array('controller' => 'accounts'),$smarty)));
		}
	}	
}
?>
